package models

import (
	"CMETO/utils"
	"time"
)

// 商品表
type Goods struct {
	// 商品Id
	Id int `json:"id" gorm:"column:id;type:int;auto_increment;primary_key;"`
	// 商品名称
	Name string `json:"name" gorm:"column:name;type:varchar(40);"`
	// 商品描述
	Description string `json:"description" gorm:"column:description;type:varchar(120);"`
	// 商品状态
	Status int `json:"status" gorm:"column:status;type:int;"`
	// 创建时间
	CreateTime string `json:"create_time" gorm:"column:create_time;type:varchar(30);"`
	// 是否删除
	IsDelete int `json:"is_delete" gorm:"column:is_delete;type:int;"`
	// 商品分类Id
	Sid int `json:"sid" gorm:"column:sid;type:int"`
	// 价格
	Price string `json:"price" gorm:"column:price;type:varchar(50);"`
	// 库存
	Stock int `json:"stock" gorm:"column:stock;type:int"`
	// 销售量
	Sales int `json:"sales" gorm:"column:sales;type:int"`
	// 主图URL
	Url string `json:"url" gorm:"column:url;type:varchar(250);"`
	// 轮播图URL
	SlideUrl string `json:"slide_url" gorm:"column:slide_url;type:varchar(250);"`
	// 详情图Url
	DetailUrl string `json:"detail_url" gorm:"column:detail_url;type:varchar(250);"`
}

// 商品表联合分类表查询
type GoodsFormat struct {
	*Goods
	Sname string `json:"sname"`
}

// 商品状态结构体
type GoodsStatus struct {
	Id     int
	Status int
}

// 插入一批商品数据
func InsertMockGoods() {
	DB.Model(&Goods{}).Create([]Goods{
		{Id: 1, Name: "《通俗唱法入门》", Sid: 4, Stock: 100, Sales: 1, Price: "99.99", Url: "http://resource.shuonihao.cn/cmeto/course/rolling_detail.jpg", SlideUrl: "http://resource.shuonihao.cn/cmeto/course/rolling_detail.jpg", DetailUrl: "http://resource.shuonihao.cn/cmeto/course/rolling_detail.jpg", Description: "唱法入门", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 2, Name: "《民族唱法入门》", Sid: 4, Stock: 100, Sales: 1, Price: "99.99", Url: "http://resource.shuonihao.cn/cmeto/course/rolling_detail.jpg", SlideUrl: "http://resource.shuonihao.cn/cmeto/course/rolling_detail.jpg", DetailUrl: "http://resource.shuonihao.cn/cmeto/course/rolling_detail.jpg", Description: "唱法入门", Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
	})
}
